package com.originskyseed.platform.count.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.originskyseed.platform.common.api.config.LoginConfig;
import com.originskyseed.platform.common.api.constant.RedisKeyConstans;
import com.originskyseed.platform.core.config.bean.ConfigManager;
import com.originskyseed.platform.core.redis.util.RedisUtil;
import com.originskyseed.platform.count.model.FinancialManage;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.filter.helper.SingleSignOnTokenHelper;
import com.originskyseed.platform.count.i18n.CountResponseMsg;
import com.originskyseed.platform.count.service.IFinancialManageService;
import com.originskyseed.platform.log.model.HomePageCache;
import com.originskyseed.platform.log.service.IHomePageCacheService;
import com.originskyseed.platform.user.model.Anchor;
import com.originskyseed.platform.user.model.AnchorLevel;
import com.originskyseed.platform.user.model.AnchorRelateLevel;
import com.originskyseed.platform.user.model.Dept;
import com.originskyseed.platform.user.model.RankingListVO;
import com.originskyseed.platform.user.model.UserInfo;
import com.originskyseed.platform.user.service.IAnchorLevelService;
import com.originskyseed.platform.user.service.IAnchorRelateLevelService;
import com.originskyseed.platform.user.service.IAnchorRelateLiveService;
import com.originskyseed.platform.user.service.IAnchorService;
import com.originskyseed.platform.user.service.IDeptService;
import com.originskyseed.platform.user.service.IParameterConfigureService;
import com.originskyseed.platform.user.service.IPlayerService;
import com.originskyseed.platform.user.service.IUserInfoService;

/**
 * 内容类统计 主播 Controller类
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/contentHomePageAnchorCount")
@BaseLocaleResource(localeFileName = "i18n_count")
public class ContentHomePageAnchorCountController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(ContentHomePageAnchorCountController.class);

	@DubboReference
	private IDeptService deptService;

	@DubboReference
	private IUserInfoService userInfoService;

	@DubboReference
	private IPlayerService playerService;

	@DubboReference
	private IAnchorService anchorService;

	@DubboReference
	private IAnchorLevelService anchorLevelService;

	@DubboReference
	private IAnchorRelateLevelService anchorRelateLevelService;

	@DubboReference
	private IAnchorRelateLiveService anchorRelateLiveService;

	@DubboReference
	private IFinancialManageService financialManageService;

	@DubboReference
	private IParameterConfigureService parameterConfigureService;

	@DubboReference
	private IHomePageCacheService homePageCacheService;

	/**
	 * 查询主播信息
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAnchorHomePage.json")
	public BaseResponseBody selectAnchorHomePage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Map<String, Object> map = new HashMap<>();
			String anchorName = null;
			String headPortrait = null;
			String levelName = null;
			String nexLevelName = null;
			BigDecimal maxValue = null;
			BigDecimal value = null;
			Long beginShowTime = 0l;
			Long rowWheatTime = 0l;

			// 获取用户id
			String userId = selectUserId(request);
			String otherAccount = selectOtherAccount(request);

			UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
			Anchor anchor = this.anchorService.selectByAnchorId(otherAccount);
			if (userInfo != null) {
				anchorName = userInfo.getName();
				headPortrait = userInfo.getHeadPortrait();

				String levelId = anchor == null ? "" : anchor.getAnchorLevelId();
				// 获取等级
				if (StringUtils.isNotBlank(levelId)) {
					AnchorLevel anchorLevel = this.anchorLevelService.selectByPrimaryKey(levelId);
					if (anchorLevel != null) {
						levelName = anchorLevel.getLevelName();
						AnchorLevel anchorLevel1 = this.anchorLevelService.selectNexLevel(anchorLevel.getEmpiricValueMax());
						if (anchorLevel1 != null) {
							nexLevelName = anchorLevel1.getLevelName();
							maxValue = anchorLevel1.getEmpiricValueMin();
						}
					}
					AnchorRelateLevel anchorRelateLevel = this.anchorRelateLevelService.selectByAnchorId(anchor.getId());
					if (anchorRelateLevel != null) {
						value = anchorRelateLevel.getEmpiricValue();
					}
				}

				Map<String, Object> query = new HashMap<>();
				query.put("anchorId", anchor == null ? "" : anchor.getId());
				query.put("type", 1);
				beginShowTime = this.anchorRelateLiveService.countAnchorLiveTime(query);
				query.put("type", 2);
				rowWheatTime = this.anchorRelateLiveService.countAnchorLiveTime(query);
			}

			map.put("anchorName", anchorName);
			map.put("headPortrait", headPortrait);
			map.put("levelName", levelName);
			map.put("nexLevelName", nexLevelName);
			map.put("maxValue", maxValue);
			map.put("value", value);
			map.put("beginShowTime", beginShowTime);
			map.put("rowWheatTime", rowWheatTime);

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询我的任务
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMyMission.json")
	public BaseResponseBody selectMyMission(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 要返回的对象
			Map<String, Object> map = new HashMap<>();

			// 获取用户id
			String userId = selectUserId(request);

			if (StringUtils.isNotBlank(userId)) {
				map = this.playerService.selectMyMission(userId);
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询我的KPI
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectMyKPI.json")
	public BaseResponseBody selectMyKPI(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型
			Integer type = this.getParameterInteger("type", null);
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 要返回的对象
			Map<String, Object> map = null;
			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIWEEK");
			} else if(type == 2 ){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIMONTH");
			}else if(type == 3 ) {
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIQUARTER");
			}else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIYEAR");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				BigDecimal target = null;
				BigDecimal complete = null;
				// 获取用户id
				String userId = selectUserId(request);
				// 获取业务员id
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(userId)) {
					FinancialManage financialManage = new FinancialManage();
					financialManage.setObjId(userId);
					financialManage.setType(2);
					financialManage.setBillCycleType(type + 1);
					List<FinancialManage> financialManageList = this.financialManageService.selectList(financialManage);
					if (financialManageList.size() > 0) {
						target = financialManageList.get(0).getAmount();
					}

					List<String> userList = new ArrayList<>();
					userList.add(otherAccount);
					complete = this.playerService.selectTiredAndFullCount(userList, type, 1);
				}
				map.put("target", target);
				map.put("complete", complete);

				// 存进redis中
				if(type==0){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIDAY",map,getCacheInvalidTime());
				} else if (type==1){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIWEEK",map,getCacheInvalidTime());
				} else if(type == 2 ){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIMONTH",map,getCacheInvalidTime());
				}else if(type == 3 ) {
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIQUARTER",map,getCacheInvalidTime());
				}else{
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectMyKPIYEAR",map,getCacheInvalidTime());
				}
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询转化率
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectConversionRate.json")
	public BaseResponseBody selectConversionRate(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Double rate = (Double) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectConversionRate");

			//redis里面没有则直接查询，并且存进redis里面
			if(rate==null){
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					// 充值数量
					Integer rechargePlayerNumber = this.playerService.selectRechargePlayerNumber(otherAccount);
					// 访问数量
					Integer visitPlayerNumber = this.playerService.selectVisitPlayerNumber(otherAccount);
					if (visitPlayerNumber == 0) {
						rate = 1.0;
					} else {
						rate = new BigDecimal((float) rechargePlayerNumber / visitPlayerNumber).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
					}

					// 存进redis
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectConversionRate",rate,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), rate);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询今日业绩
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTodayAchievement.json")
	public BaseResponseBody selectTodayAchievement(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTodayAchievement");

			//redis里面没有则直接查询，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String otherAccount = selectOtherAccount(request);
				if (StringUtils.isNotBlank(otherAccount)) {
					// 今日日期
					String today = getToday();
					// 昨天日期
					String yesterday = getYesterday();

					// 今日消费总额，昨日消费总额
					Map<String, Object> query = new HashMap<>();
					List<String> anchorIdList = new ArrayList<>();
					anchorIdList.add(otherAccount);
					query.put("list", anchorIdList);

					query.put("startTime", today);
					query.put("endTime", today);
					BigDecimal todayAmount = this.playerService.selectAnchorProfit(query);
					query.put("startTime", yesterday);
					query.put("endTime", yesterday);
					BigDecimal yesterdayAmount = this.playerService.selectAnchorProfit(query);

					// 计算比率
					map.put("todayProfit", todayAmount.multiply(new BigDecimal("0.3")));
					map.put("yesterdayProfit", yesterdayAmount.multiply(new BigDecimal("0.3")));
					if (yesterdayAmount.compareTo(BigDecimal.ZERO) != 0) {
						map.put("rate", todayAmount.subtract(yesterdayAmount).divide(yesterdayAmount, 2));
					} else {
						map.put("rate", 1);
					}

					// 存到redis中
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTodayAchievement",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质主播排行
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectQualityAnchorRanking.json")
	public BaseResponseBody selectQualityAnchorRanking(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			List<RankingListVO> rankingListVOList = (List<RankingListVO>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectQualityAnchorRanking");
			// redis里面没有则直接查询，并且存进redis里面
			if(rankingListVOList==null){
				int size = this.getParameterInteger("size", 50);
				// 获取用户信息
				String userId = this.selectUserId(request);
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
				if (userInfo != null) {
					// 查询同级小组的所有主播id
					List<String> deptList = this.selectGroupId(userInfo.getDeptId());
					List<String> anchorList = this.userInfoService.selectAnchorOtherIdsByDeptIds(deptList);

					Map<String, Object> query = new HashMap<>();
					query.put("size", size);
					query.put("list", anchorList);
					rankingListVOList = this.playerService.selectQualityAnchorRanking(query);
					for (RankingListVO rankingListVO : rankingListVOList) {
						UserInfo userInfo1 = this.userInfoService.selectByOtherAccount(rankingListVO.getAnchorId());
						if (userInfo1 != null) {
							rankingListVO.setHeadPortrait(userInfo1.getHeadPortrait());
						}
					}

					// 存进redis中
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectQualityAnchorRanking",rankingListVOList,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), rankingListVOList);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询房间曝光量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectRoomExposure.json")
	public BaseResponseBody selectRoomExposure(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 类型 0日，1周，2月，3季，4年
			Integer type = this.getParameterInteger("type", null);
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 要返回的数据
			Map<String, Object> map = null;
			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				String userId = this.selectUserId(request);
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
				if (userInfo != null) {
					// 查询同级小组的所有主播id
					List<String> deptList = this.selectGroupId(userInfo.getDeptId());
					List<String> anchorList = this.userInfoService.selectAnchorOtherIdsByDeptIds(deptList);
					map = this.playerService.selectVisitsNumber(type, anchorList);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectRoomExposureMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 公会用户消费TOP榜
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectConsumptionRanking.json")
	public BaseResponseBody selectConsumptionRanking(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			List<RankingListVO> rankingListVOList = (List<RankingListVO>) RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectConsumptionRanking");

			// redis里面没有则直接查询，并且存进redis里面
			if(rankingListVOList==null){
				int size = this.getParameterInteger("size", 50);
				// 获取用户信息
				String userId = this.selectUserId(request);
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
				if (userInfo != null) {
					// 查询同级小组的所有主播id
					List<String> deptList = this.selectGroupId(userInfo.getDeptId());
					List<String> anchorList = this.userInfoService.selectAnchorOtherIdsByDeptIds(deptList);

					Map<String, Object> query = new HashMap<>();
					query.put("size", size);
					query.put("list", anchorList);
					if (anchorList.size() > 0) {
						rankingListVOList = this.playerService.selectConsumptionRanking(query);

						// 存进redis中
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectConsumptionRanking",rankingListVOList,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), rankingListVOList);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询渠道下所有小组
	 * 
	 * @param id
	 * @throws Exception
	 */
	private List<String> selectGroupId(String id) throws Exception {
		List<String> list = new ArrayList<>();
		list.add(id);
		Dept dept = this.deptService.selectByPrimaryKey(id);
		if (dept != null) {
			List<Dept> deptList = this.deptService.selectByParentCode(dept.getParentCode());
			for (Dept dept1 : deptList) {
				list.add(dept1.getId());
			}
		}
		return list;
	}

	/**
	 * 获取用户id
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	private String selectUserId(HttpServletRequest request) throws Exception {
		// 业务员id
		String userId = this.getParameterString("deptId", null);
		if (StringUtils.isBlank(userId)) {
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			userId = userInfo.getId();
		}
		return userId;
	}

	/**
	 * 获取业务员id
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	private String selectOtherAccount(HttpServletRequest request) throws Exception {
		String otherAccount = "";
		// 业务员id
		String userId = this.getParameterString("deptId", null);
		if (StringUtils.isBlank(userId)) {
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			if (userInfo != null) {
				otherAccount = userInfo.getOtherAccount();
			}
		} else {
			UserInfo userInfo = this.userInfoService.selectByPrimaryKey(userId);
			if (userInfo != null) {
				otherAccount = userInfo.getOtherAccount();
			}
		}
		return otherAccount;
	}

	// 日期格式化
	private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * 获得本周的第一天，周一
	 *
	 * @return
	 */
	public String getToday() {
		Calendar c = Calendar.getInstance();
		return sdf.format(c.getTime());
	}

	/**
	 * 获得昨天的日期
	 *
	 * @return
	 */
	public String getYesterday() {
		Calendar c = Calendar.getInstance();
		try {
			c.add(Calendar.DATE, -1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sdf.format(c.getTime());
	}


	/**
	 * 获取失效时间
	 * @return
	 */
	private long getCacheInvalidTime(){
		LoginConfig loginConfig = ConfigManager.getInstance().parseObject(LoginConfig.class);
		long timeOut = 7200000;
		if(loginConfig!=null && loginConfig.getCacheInvalidTime()!=null){
			timeOut = loginConfig.getCacheInvalidTime()*60*1000;
		}
		return timeOut;
	}
}